# -*- coding:utf-8 -*-
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

from utils.wx_helper import content_to_dict, deal_subscribe_event, deal_click_action, deal_text_input


@csrf_exempt
def gate_view(request):
    """
    method: GET/POST
    api: /wx/gate/
    """
    # return HttpResponse(request.GET['echostr'])
    message = content_to_dict(request.body)
    content = deal_subscribe_event(message)
    if not content:
        content = deal_click_action(message)
    if not content:
        content = deal_text_input(message)
    return HttpResponse(content)
